package servlets;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringEscapeUtils;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;


@SuppressWarnings("serial")
public class RegisterServlet extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		//String content = req.getParameter("content");
		String email = StringEscapeUtils.escapeHtml3(req.getParameter("email"));
		String username = StringEscapeUtils.escapeHtml3(req.getParameter("username"));
		String password = DigestUtils.sha1Hex(StringEscapeUtils.escapeHtml3(req.getParameter("password")));
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Entity user = new Entity("Utilisateur", email);
        user.setProperty("email", email);
        user.setProperty("username", username);
        user.setProperty("password", password);
        user.setProperty("points", 100);
		datastore.put(user);
		
        resp.sendRedirect("/accueil.html");

	}
}
